<?php
namespace app\erp\model;
use think\Model;
class PayLogdb extends Model{
    protected $pk = 'pay_log_id';
    
    protected $name = 'pay_log';
    
    protected $type = [
        'create_time' => 'timestamp:Y-m-d H:i',
    ];
    protected $autoWriteTimestamp = true;
    public $param = array();
    // 自动完成
    protected $insert = [
        'partner_id' => PARTNER_ID,
        'site_id'
    ];
    protected function setSiteIdAttr($value)
    {
        if(!$value){
            return SITE_ID;
        }
        if ($value == 0) {
            return null;
        }
        return $value;
    }
    // 基础查询
    public function base($query)
    {
        $query->where('partner_id', PARTNER_ID);
        if (isset($this->param['site_id'])) {
            if ($this->param['site_id'] == 0 || $this->param['site_id'] == '') {
                $query->where('site_id', null);
            } elseif($this->param['site_id'] != -1) {
                $query->where('site_id', $this->param['site_id']);
            }
        } else {
            if (! empty(SITE_ID)) {
                $query->where('site_id', SITE_ID);
            } else {
                $query->where('site_id', null);
            }
        }
        if (isset($this->param['order_no']) && $this->param['order_no']) {
            $query->orderNo($this->param['order_no']);
        }
    }
    public function ajaxSave(){
        $this->allowField(true)->save($this->param);
        return 'success';
    }
}
